<?php
namespace app\index\model;
use think\Model;
use app\index\model\Filex;
use app\index\model\Modelx;

class Channel extends Model
{
	protected $where=array("status"=>1);
	public function getChannel(){
		$data=channel::where($this->where)->order("sort asc , id DESC")->select();
		$filex=new Filex();	
		$modelx=new modelx();	
		
		$mess=array_map(function($v){
			return $v->toArray();
		}, $data);
		for ($i=0; $i < count($mess); $i++) { 
			if($mess[$i]['thumb']){
				$mess[$i]['annexes']=$filex->getThumbById($mess[$i]['thumb']);
			}
			$mess[$i]['contro']=$modelx->getFieldById($mess[$i]['modelx'],'mark');
			// $mess[$i]['vpage']=db("template")->where("id=".$mess[$i]['template'])->value('vpage');
			// if(!$mess[$i]['vpage']){
			// 	$mess[$i]['vpage']="index";
			// }
		}
		return $mess;
	}
	public function getMarkByid($id){		       
		$modelx=Channel::where('status',1)->value('modelx');
		// echo $modelx;
		$moModel=new Modelx(); 
		$mark=$moModel->getMarkByid($modelx);
		// echo $mark;
		return $mark;
	}
	public function getFieldById($id,$field){
		$data=Channel::where('id',$id)->value($field);

		return $data;
	}
	public function getLeftChannel($pid){
		$this->where['pid']=$pid;
		// print_r($this->where);exit;
		$data=Channel::where($this->where)->order("sort asc , id DESC")->select();
		$filex=new Filex();	
		$modelx=new modelx();
		
		$mess=array_map(function($v){
			return $v->toArray();
		}, $data);
		for ($i=0; $i < count($mess); $i++) { 
			if($mess[$i]['thumb']){
				$mess[$i]['annexes']=$filex->getThumbById($mess[$i]['thumb']);
			}
			$mess[$i]['contro']=$modelx->getFieldById($mess[$i]['modelx'],'mark');
			// $mess[$i]['vpage']=db("template")->where("id=".$mess[$i]['template'])->value('vpage');
			// if(!$mess[$i]['vpage']){
			// 	$mess[$i]['vpage']="index";
			// }
		}
		return $mess;
	}
	public function getIdByPid($pid){
		$this->where['pid']=$pid;
		$data=Channel::where($this->where)->order("sort asc ,id desc")->value('id');

		return $data;
	}
}